package gt.edu.usac.viewcontroller.backing.app;

import gt.edu.usac.model.am.AppModuleImpl;
import gt.edu.usac.model.vo.idiomaNivelSeccionViewImpl;
import gt.edu.usac.model.vo.idiomaProfesorView2Impl;
import gt.edu.usac.model.vo.idiomaProfesorViewImpl;
import gt.edu.usac.model.vo.idiomaViewImpl;
import gt.edu.usac.model.vo.personaParamsViewImpl;
import gt.edu.usac.model.vo.profesorImpViewImpl;
import gt.edu.usac.model.vo.profesorParamViewImpl;
import gt.edu.usac.model.vo.profesorViewImpl;
import gt.edu.usac.viewcontroller.utils.JSFUtils;

import javax.faces.component.UISelectItems;
import javax.faces.component.html.HtmlForm;

import javax.faces.context.FacesContext;
import javax.faces.el.ValueBinding;

import oracle.adf.model.BindingContext;
import oracle.adf.model.binding.DCDataControl;
import oracle.adf.view.faces.component.core.data.CoreColumn;
import oracle.adf.view.faces.component.core.data.CoreTable;
import oracle.adf.view.faces.component.core.data.CoreTableSelectOne;
import oracle.adf.view.faces.component.core.input.CoreInputText;
import oracle.adf.view.faces.component.core.input.CoreSelectInputDate;
import oracle.adf.view.faces.component.core.input.CoreSelectOneChoice;
import oracle.adf.view.faces.component.core.layout.CorePanelForm;
import oracle.adf.view.faces.component.core.layout.CorePanelGroup;
import oracle.adf.view.faces.component.core.layout.CorePanelHeader;
import oracle.adf.view.faces.component.core.layout.CorePanelHorizontal;
import oracle.adf.view.faces.component.core.nav.CoreCommandButton;
import oracle.adf.view.faces.component.core.nav.CoreCommandLink;
import oracle.adf.view.faces.component.core.output.CoreObjectSpacer;
import oracle.adf.view.faces.component.core.output.CoreOutputText;

import oracle.binding.BindingContainer;
import oracle.binding.OperationBinding;

import oracle.jbo.ApplicationModule;
import oracle.jbo.AttributeDef;
import oracle.jbo.AttributeList;
import oracle.jbo.Key;
import oracle.jbo.Row;
import oracle.jbo.RowSetIterator;
import oracle.jbo.domain.DBSequence;
import oracle.jbo.server.AttributeListImpl;
import oracle.jbo.server.SessionImpl;

public class AdminProfesores {
    private HtmlForm form1;
    private CorePanelHeader panelHeader1;
    private CorePanelGroup panelGroup2;
    private CorePanelGroup panelGroup3;
    private CoreCommandButton commandButton1;
    private CoreCommandButton commandButton2;
    private BindingContainer bindings;
    private CoreTable table2;
    private CoreColumn column19;
    private CoreColumn column17;
    private CoreCommandLink commandLink3;
    private CoreCommandLink commandLink4;
    private CorePanelForm panelForm1;
    private CoreInputText inputText1;
    private CoreInputText inputText2;
    private CoreInputText inputText4;
    private CoreInputText inputText7;
    private CoreInputText inputText8;
    private CoreInputText inputText9;
    private CoreSelectInputDate selectInputDate1;
    private CoreInputText inputText11;
    private CoreInputText inputText12;
    private CoreInputText inputText13;
    private CoreInputText inputText14;
    private CoreInputText inputText15;
    private CoreInputText inputText16;
    private CoreSelectOneChoice selectOneChoice1;
    private UISelectItems selectItems1;
    private CoreSelectOneChoice selectOneChoice2;
    private UISelectItems selectItems2;
    private CorePanelGroup panelGroup21;
    private CorePanelHeader panelHeader2;
    private CorePanelHorizontal panelHorizontal1;
    private CoreTable table1;
    private CoreColumn column1;
    private CoreOutputText outputText2;
    private CoreTableSelectOne tableSelectOne1;
    private CoreTable table3;
    private CoreColumn column3;
    private CoreOutputText outputText1;
    private CoreTableSelectOne tableSelectOne3;
    private CorePanelGroup panelGroup4;
    private CoreCommandButton commandButton3;
    private CoreCommandButton commandButton21;
    private CoreCommandButton commandButton4;
    private CoreColumn column21;
    private CorePanelHorizontal panelHorizontal2;
    private CoreOutputText outputText11;
    private CoreOutputText outputText3;
    private CoreObjectSpacer objectSpacer1;
    private CoreSelectOneChoice selectOneChoice3;
    private UISelectItems selectItems3;
    private CoreColumn column28;
    private CoreOutputText outputText4;
    private CoreColumn column2;
    private CoreOutputText outputText5;
    private CoreColumn column27;
    private CoreOutputText outputText6;
    private CoreColumn column30;
    private CoreOutputText outputText7;
    private CoreColumn column20;
    private CoreOutputText outputText8;
    private CoreColumn column22;
    private CoreOutputText outputText9;
    private CoreColumn column23;
    private CoreOutputText outputText10;
    private CoreSelectOneChoice selectOneChoice4;
    private UISelectItems selectItems4;

    public void setForm1(HtmlForm form1) {
        this.form1 = form1;
    }

    public HtmlForm getForm1() {
        return form1;
    }

    public void setPanelHeader1(CorePanelHeader panelHeader1) {
        this.panelHeader1 = panelHeader1;
    }

    public CorePanelHeader getPanelHeader1() {
        return panelHeader1;
    }

    public void setPanelGroup2(CorePanelGroup panelGroup2) {
        this.panelGroup2 = panelGroup2;
    }

    public CorePanelGroup getPanelGroup2() {
        return panelGroup2;
    }


    public void setPanelGroup3(CorePanelGroup panelGroup3) {
        this.panelGroup3 = panelGroup3;
    }

    public CorePanelGroup getPanelGroup3() {
        return panelGroup3;
    }


    public void setCommandButton1(CoreCommandButton commandButton1) {
        this.commandButton1 = commandButton1;
    }

    public CoreCommandButton getCommandButton1() {
        return commandButton1;
    }

    public void setCommandButton2(CoreCommandButton commandButton2) {
        this.commandButton2 = commandButton2;
    }

    public CoreCommandButton getCommandButton2() {
        return commandButton2;
    }


    public BindingContainer getBindings() {
        return this.bindings;
    }

    public void setBindings(BindingContainer bindings) {
        this.bindings = bindings;
    }

    public String commandLink2_action() {
        BindingContainer bindings = getBindings();
        OperationBinding operationBinding = 
            bindings.getOperationBinding("setCurrentRowWithKey");
        Object result = operationBinding.execute();
        if (!operationBinding.getErrors().isEmpty()) {
            return null;
        }
        
        JSFUtils.setExpressionValue("#{bindings.mostrar.inputValue}",true);
        return null;
    }

    public String commandButton2_action() {
        BindingContainer bindings = getBindings();
        OperationBinding operationBinding = 
            bindings.getOperationBinding("Rollback");
        Object result = operationBinding.execute();
        if (!operationBinding.getErrors().isEmpty()) {
            return null;
        }
        JSFUtils.setExpressionValue("#{bindings.mostrar.inputValue}",false);
        return null;
    }

    public String commandButton1_action() {
        BindingContainer bindings = getBindings();
        OperationBinding operationBinding = 
            bindings.getOperationBinding("Commit");
        Object result = operationBinding.execute();
        if (!operationBinding.getErrors().isEmpty()) {
            return null;
        }
        JSFUtils.setExpressionValue("#{bindings.mostrar.inputValue}",false);
        return null;
    }

    public String commandLink1_action() {
        BindingContainer bindings = getBindings();
        OperationBinding operationBinding = 
            bindings.getOperationBinding("setCurrentRowWithKey");
        Object result = operationBinding.execute();
        if (!operationBinding.getErrors().isEmpty()) {
            return null;
        }
        AppModuleImpl service = getAppModule();
        profesorParamViewImpl profesor = service.getprofesorParamView1();
        profesorImpViewImpl profesor1 = service.getprofesorImpView1();
        profesor.setprofe(profesor1.getCurrentRow().getAttribute("IdProfesor").toString());
        personaParamsViewImpl persona= service.getpersonaParamsView1();
        persona.setpersona(profesor1.getCurrentRow().getAttribute("IdPersona").toString());        
        profesor.executeQuery();
        profesor.setCurrentRow(profesor.first());
        try{
        profesor.removeCurrentRow();
        persona.executeQuery();
        persona.setCurrentRow(persona.first());
        persona.removeCurrentRow();
        service.getDBTransaction().commit();
        }
        catch(Exception ex){
            profesor.getDBTransaction().rollback();
        }
       /* profesorViewImpl profesor = service.getprofesorView1();
        profesorImpViewImpl profesor1 = service.getprofesorImpView1();         
        Key key= new Key(new Object[] {profesor1.getCurrentRow().getAttribute("IdProfesor")});         
        Row r= profesor.getRow(key);        
        RowSetIterator rsi= profesor.createRowSetIterator("iterador");
        r=rsi.getRow(key);
        profesor.setCurrentRow(r);   
        profesor.removeCurrentRow();
        service.getTransaction().commit();
        DBSequence idProfesor=(DBSequence)profesor1.getCurrentRow().getAttribute("IdProfesor");
        Key key= new Key(new Object[] { idProfesor });               
        RowSetIterator rsi= profesor.getRowSetIterator();
        profesor.set
        Row r=rsi.findByKey(key, 1)[0];
        rsi.setCurrentRow(r);
        System.out.println(r.getAttribute("Categoria"));
        /*profesor.removeCurrentRow();
        service.getDBTransaction().commit();*/
        return null;
    }
    public AppModuleImpl getAppModule() {
        FacesContext ctx = FacesContext.getCurrentInstance();
        ValueBinding vb = ctx.getApplication().createValueBinding("#{data}");
        BindingContext bc = (BindingContext)vb.getValue(ctx);
        DCDataControl dc = bc.findDataControl("AppModuleDataControl");
        ApplicationModule am = (ApplicationModule)dc.getDataProvider();
        return (AppModuleImpl)am;
    }

    public void setTable2(CoreTable table2) {
        this.table2 = table2;
    }

    public CoreTable getTable2() {
        return table2;
    }


    public void setColumn19(CoreColumn column19) {
        this.column19 = column19;
    }

    public CoreColumn getColumn19() {
        return column19;
    }


    public void setColumn17(CoreColumn column17) {
        this.column17 = column17;
    }

    public CoreColumn getColumn17() {
        return column17;
    }


    public void setCommandLink3(CoreCommandLink commandLink3) {
        this.commandLink3 = commandLink3;
    }

    public CoreCommandLink getCommandLink3() {
        return commandLink3;
    }

    public void setCommandLink4(CoreCommandLink commandLink4) {
        this.commandLink4 = commandLink4;
    }

    public CoreCommandLink getCommandLink4() {
        return commandLink4;
    }

    public void setPanelForm1(CorePanelForm panelForm1) {
        this.panelForm1 = panelForm1;
    }

    public CorePanelForm getPanelForm1() {
        return panelForm1;
    }

    public void setInputText1(CoreInputText inputText1) {
        this.inputText1 = inputText1;
    }

    public CoreInputText getInputText1() {
        return inputText1;
    }

    public void setInputText2(CoreInputText inputText2) {
        this.inputText2 = inputText2;
    }

    public CoreInputText getInputText2() {
        return inputText2;
    }


    public void setInputText4(CoreInputText inputText4) {
        this.inputText4 = inputText4;
    }

    public CoreInputText getInputText4() {
        return inputText4;
    }


    public void setInputText7(CoreInputText inputText7) {
        this.inputText7 = inputText7;
    }

    public CoreInputText getInputText7() {
        return inputText7;
    }

    public void setInputText8(CoreInputText inputText8) {
        this.inputText8 = inputText8;
    }

    public CoreInputText getInputText8() {
        return inputText8;
    }

    public void setInputText9(CoreInputText inputText9) {
        this.inputText9 = inputText9;
    }

    public CoreInputText getInputText9() {
        return inputText9;
    }

    public void setSelectInputDate1(CoreSelectInputDate selectInputDate1) {
        this.selectInputDate1 = selectInputDate1;
    }

    public CoreSelectInputDate getSelectInputDate1() {
        return selectInputDate1;
    }


    public void setInputText11(CoreInputText inputText11) {
        this.inputText11 = inputText11;
    }

    public CoreInputText getInputText11() {
        return inputText11;
    }

    public void setInputText12(CoreInputText inputText12) {
        this.inputText12 = inputText12;
    }

    public CoreInputText getInputText12() {
        return inputText12;
    }

    public void setInputText13(CoreInputText inputText13) {
        this.inputText13 = inputText13;
    }

    public CoreInputText getInputText13() {
        return inputText13;
    }

    public void setInputText14(CoreInputText inputText14) {
        this.inputText14 = inputText14;
    }

    public CoreInputText getInputText14() {
        return inputText14;
    }

    public void setInputText15(CoreInputText inputText15) {
        this.inputText15 = inputText15;
    }

    public CoreInputText getInputText15() {
        return inputText15;
    }

    public void setInputText16(CoreInputText inputText16) {
        this.inputText16 = inputText16;
    }

    public CoreInputText getInputText16() {
        return inputText16;
    }

    public void setSelectOneChoice1(CoreSelectOneChoice selectOneChoice1) {
        this.selectOneChoice1 = selectOneChoice1;
    }

    public CoreSelectOneChoice getSelectOneChoice1() {
        return selectOneChoice1;
    }

    public void setSelectItems1(UISelectItems selectItems1) {
        this.selectItems1 = selectItems1;
    }

    public UISelectItems getSelectItems1() {
        return selectItems1;
    }


    public void setSelectOneChoice2(CoreSelectOneChoice selectOneChoice2) {
        this.selectOneChoice2 = selectOneChoice2;
    }

    public CoreSelectOneChoice getSelectOneChoice2() {
        return selectOneChoice2;
    }

    public void setSelectItems2(UISelectItems selectItems2) {
        this.selectItems2 = selectItems2;
    }

    public UISelectItems getSelectItems2() {
        return selectItems2;
    }


    public void setPanelGroup21(CorePanelGroup panelGroup21) {
        this.panelGroup21 = panelGroup21;
    }

    public CorePanelGroup getPanelGroup21() {
        return panelGroup21;
    }

    public void setPanelHeader2(CorePanelHeader panelHeader2) {
        this.panelHeader2 = panelHeader2;
    }

    public CorePanelHeader getPanelHeader2() {
        return panelHeader2;
    }

    public void setPanelHorizontal1(CorePanelHorizontal panelHorizontal1) {
        this.panelHorizontal1 = panelHorizontal1;
    }

    public CorePanelHorizontal getPanelHorizontal1() {
        return panelHorizontal1;
    }

    public void setTable1(CoreTable table1) {
        this.table1 = table1;
    }

    public CoreTable getTable1() {
        return table1;
    }

    public void setColumn1(CoreColumn column1) {
        this.column1 = column1;
    }

    public CoreColumn getColumn1() {
        return column1;
    }

    public void setOutputText2(CoreOutputText outputText2) {
        this.outputText2 = outputText2;
    }

    public CoreOutputText getOutputText2() {
        return outputText2;
    }

    public void setTableSelectOne1(CoreTableSelectOne tableSelectOne1) {
        this.tableSelectOne1 = tableSelectOne1;
    }

    public CoreTableSelectOne getTableSelectOne1() {
        return tableSelectOne1;
    }


    public String commandButton3_action() {        
            AppModuleImpl service = getAppModule();
            idiomaProfesorView2Impl  asigna = service.getidiomaProfesorView2_2();            
            idiomaViewImpl  idioma = service.getidiomaView1();
            RowSetIterator iterador=asigna.createRowSetIterator("iter");
            iterador.reset();            
            while(iterador.hasNext()){
                Row row=iterador.next();            
                if(  new DBSequence((oracle.jbo.domain.Number)row.getAttribute("IdIdioma")).equals(idioma.getCurrentRow().getAttribute("IdIdioma"))){
                        iterador.closeRowSetIterator();
                        return null;
                    }   
            }
            iterador.closeRowSetIterator();
            Row row = asigna.createRow();
            row.setAttribute("IdIdioma",idioma.getCurrentRow().getAttribute("IdIdioma"));
            asigna.insertRow(row);            
        
        return null;
    }
    
   

    public String commandButton21_action() {
        AppModuleImpl service = getAppModule();
        idiomaProfesorView2Impl  asigna = service.getidiomaProfesorView2_2();
        if(asigna.getCurrentRow()!=null){
           asigna.removeCurrentRow();
        }         
        return null;
    }

    public void setTable3(CoreTable table3) {
        this.table3 = table3;
    }

    public CoreTable getTable3() {
        return table3;
    }

    public void setColumn3(CoreColumn column3) {
        this.column3 = column3;
    }

    public CoreColumn getColumn3() {
        return column3;
    }

    public void setOutputText1(CoreOutputText outputText1) {
        this.outputText1 = outputText1;
    }

    public CoreOutputText getOutputText1() {
        return outputText1;
    }

    public void setTableSelectOne3(CoreTableSelectOne tableSelectOne3) {
        this.tableSelectOne3 = tableSelectOne3;
    }

    public CoreTableSelectOne getTableSelectOne3() {
        return tableSelectOne3;
    }


    public void setPanelGroup4(CorePanelGroup panelGroup4) {
        this.panelGroup4 = panelGroup4;
    }

    public CorePanelGroup getPanelGroup4() {
        return panelGroup4;
    }

    public void setCommandButton3(CoreCommandButton commandButton3) {
        this.commandButton3 = commandButton3;
    }

    public CoreCommandButton getCommandButton3() {
        return commandButton3;
    }

    public void setCommandButton21(CoreCommandButton commandButton21) {
        this.commandButton21 = commandButton21;
    }

    public CoreCommandButton getCommandButton21() {
        return commandButton21;
    }


    public void setCommandButton4(CoreCommandButton commandButton4) {
        this.commandButton4 = commandButton4;
    }

    public CoreCommandButton getCommandButton4() {
        return commandButton4;
    }


    public void setColumn21(CoreColumn column21) {
        this.column21 = column21;
    }

    public CoreColumn getColumn21() {
        return column21;
    }


    public void setPanelHorizontal2(CorePanelHorizontal panelHorizontal2) {
        this.panelHorizontal2 = panelHorizontal2;
    }

    public CorePanelHorizontal getPanelHorizontal2() {
        return panelHorizontal2;
    }

    public void setOutputText11(CoreOutputText outputText11) {
        this.outputText11 = outputText11;
    }

    public CoreOutputText getOutputText11() {
        return outputText11;
    }

    public void setOutputText3(CoreOutputText outputText3) {
        this.outputText3 = outputText3;
    }

    public CoreOutputText getOutputText3() {
        return outputText3;
    }

    public void setObjectSpacer1(CoreObjectSpacer objectSpacer1) {
        this.objectSpacer1 = objectSpacer1;
    }

    public CoreObjectSpacer getObjectSpacer1() {
        return objectSpacer1;
    }


    public void setSelectOneChoice3(CoreSelectOneChoice selectOneChoice3) {
        this.selectOneChoice3 = selectOneChoice3;
    }

    public CoreSelectOneChoice getSelectOneChoice3() {
        return selectOneChoice3;
    }

    public void setSelectItems3(UISelectItems selectItems3) {
        this.selectItems3 = selectItems3;
    }

    public UISelectItems getSelectItems3() {
        return selectItems3;
    }

    public void setColumn28(CoreColumn column28) {
        this.column28 = column28;
    }

    public CoreColumn getColumn28() {
        return column28;
    }

    public void setOutputText4(CoreOutputText outputText4) {
        this.outputText4 = outputText4;
    }

    public CoreOutputText getOutputText4() {
        return outputText4;
    }

    public void setColumn2(CoreColumn column2) {
        this.column2 = column2;
    }

    public CoreColumn getColumn2() {
        return column2;
    }

    public void setOutputText5(CoreOutputText outputText5) {
        this.outputText5 = outputText5;
    }

    public CoreOutputText getOutputText5() {
        return outputText5;
    }

    public void setColumn27(CoreColumn column27) {
        this.column27 = column27;
    }

    public CoreColumn getColumn27() {
        return column27;
    }

    public void setOutputText6(CoreOutputText outputText6) {
        this.outputText6 = outputText6;
    }

    public CoreOutputText getOutputText6() {
        return outputText6;
    }

    public void setColumn30(CoreColumn column30) {
        this.column30 = column30;
    }

    public CoreColumn getColumn30() {
        return column30;
    }

    public void setOutputText7(CoreOutputText outputText7) {
        this.outputText7 = outputText7;
    }

    public CoreOutputText getOutputText7() {
        return outputText7;
    }

    public void setColumn20(CoreColumn column20) {
        this.column20 = column20;
    }

    public CoreColumn getColumn20() {
        return column20;
    }

    public void setOutputText8(CoreOutputText outputText8) {
        this.outputText8 = outputText8;
    }

    public CoreOutputText getOutputText8() {
        return outputText8;
    }

    public void setColumn22(CoreColumn column22) {
        this.column22 = column22;
    }

    public CoreColumn getColumn22() {
        return column22;
    }

    public void setOutputText9(CoreOutputText outputText9) {
        this.outputText9 = outputText9;
    }

    public CoreOutputText getOutputText9() {
        return outputText9;
    }

    public void setColumn23(CoreColumn column23) {
        this.column23 = column23;
    }

    public CoreColumn getColumn23() {
        return column23;
    }

    public void setOutputText10(CoreOutputText outputText10) {
        this.outputText10 = outputText10;
    }

    public CoreOutputText getOutputText10() {
        return outputText10;
    }

    public void setSelectOneChoice4(CoreSelectOneChoice selectOneChoice4) {
        this.selectOneChoice4 = selectOneChoice4;
    }

    public CoreSelectOneChoice getSelectOneChoice4() {
        return selectOneChoice4;
    }

    public void setSelectItems4(UISelectItems selectItems4) {
        this.selectItems4 = selectItems4;
    }

    public UISelectItems getSelectItems4() {
        return selectItems4;
    }
}
